<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::post('payment/wechat/notify', 'Api\PaymentController@wechatNotify')->name('payment.wechat.notify');
Route::post('payment/wechat/refund_notify', 'Api\PaymentController@wechatRefundNotify')->name('payment.wechat.refund_notify');

Route::group(['namespace' => 'Api','middleware' => ['cors']], function () {
    //测试签名
    Route::post('test/test_signature','TestController@testSignature')->name('api.test.test_signature');
    //小程序根据code获取
    Route::get('wechatmini/get_session','WechatController@getSession')->name('api.wechatmini.get_session');
    Route::get('wechatmini/test','WechatController@test')->name('api.wechatmini.test');

    //注册用户
    Route::post('user/register','WechatController@register')->name('api.user.register');
    //授权登录后保存用户信息
    Route::post('user/store','WechatController@store')->name('api.user.store');

    //获取电子面单余额
    Route::get('express/quota/get','ExpressController@getQuota')->name('api.express.quota.get');
    //更新打印员
    Route::get('express/printer/update','ExpressController@updatePrinter')->name('api.express.printer.update');
    Route::get('express/printer/getall','ExpressController@getPrinter')->name('api.express.printer.getall');
    Route::get('express/path/get','ExpressController@getPath')->name('api.express.path.get');
    Route::get('express/order/get','ExpressController@getOrder')->name('api.express.order.get');
    Route::get('express/order/input','ExpressController@inputOrder')->name('api.express.order.input');
    Route::get('express/order/cancel','ExpressController@cancelOrder')->name('api.express.order.cancel');
});

/**
 * 无需授权登录
 */
Route::group(['namespace' => 'Api','middleware' => ['cors']], function () {
    Route::get('user/recommend_user_info','UserController@recommendUserInfo')->name('api.user.recommend_user_info');
    Route::get('coupon/new_user_coupon','CouponController@newUserCoupon')->name('api.coupon.new_user_coupon');
});


Route::group(['namespace' => 'Api','middleware' => ['cors','check_user_login']], function () {
    Route::get('homepage/index','HomepageController@index')->name('api.homepage.index');
    Route::get('homepage/randSell','HomepageController@randSell')->name('api.homepage.randSell');
    Route::get('homepage/books','HomepageController@books')->name('api.homepage.books');
    Route::get('homepage/keywords','HomepageController@keywords')->name('api.homepage.keywords');
    Route::delete('homepage/keywords','HomepageController@deleteKeywords')->name('api.homepage.delete_keywords');

    Route::get('book_list/index','BookListController@index')->name('api.book_list.index');
    Route::get('book_list/show','BookListController@show')->name('api.book_list.show');

    Route::get('book/categories','BookController@categories')->name('api.book.categories');
    Route::get('book/search','BookController@search')->name('api.book.search');
    Route::get('books','BookController@index')->name('api.book.index');
    Route::get('book/show','BookController@show')->name('api.book.show');
    Route::get('book/comments','BookController@comments')->name('api.book.comments');
    Route::get('book/relations','BookController@relations')->name('api.book.relations');
    Route::get('book/author','BookController@author')->name('api.book.author');
    Route::post('book/remind','BookController@remind')->name('api.book.remind');

    //购物车
    Route::post('cart','CartController@store')->name('api.cart.store');
    Route::post('cart/selected','CartController@selected')->name('api.cart.selected');
    Route::get('cart','CartController@show')->name('api.cart.show');
    Route::delete('cart','CartController@destroy')->name('api.cart.destroy');

    Route::post('order/submit','OrderController@submit')->name('api.order.submit');
    Route::get('orders','OrderController@index')->name('api.order.index');
    Route::get('order/express_fee','OrderController@expressFee')->name('api.order.express_fee');
    Route::post('order','OrderController@store')->name('api.order.store');
    Route::get('order/show','OrderController@show')->name('api.order.show');
    Route::post('order/apply_refund', 'OrderController@applyRefund')->name('api.order.apply_refund');
    Route::get('order/coupons', 'OrderController@coupons')->name('api.order.coupons');
    Route::get('order/express', 'OrderController@express')->name('api.order.express');

    Route::get('user_address/areas','UserAddressController@areas')->name('api.user_address.areas');
    Route::get('user_addresses','UserAddressController@index')->name('api.user_address.index');
    Route::post('user_address','UserAddressController@store')->name('api.user_address.store');
    Route::put('user_address/update','UserAddressController@update')->name('api.user_address.update');
    Route::get('user_address/show','UserAddressController@show')->name('api.user_address.show');
    Route::delete('user_address/destroy','UserAddressController@destroy')->name('api.user_address.destroy');

    Route::get('areas','AreaController@index')->name('api.area.index');
    Route::get('areas/store','AreaController@storeFile')->name('api.area.store');

    //名家专栏
    Route::get('authors','AuthorController@index')->name('api.author.index');
    Route::get('author/show','AuthorController@show')->name('api.author.index');

    Route::get('user/home','UserController@home')->name('api.user.home');
    Route::get('user/check_official_account','UserController@checkOfficialAccount')->name('api.user.check_official_account');
    Route::get('user/account_record','UserController@accountRecords')->name('api.user.account_record');
    Route::get('user/book_remind','UserController@bookRemind')->name('api.user.book_remind');
    Route::post('user/get_money','UserController@getMoney')->name('api.user.get_money');
    Route::get('user/order_books','UserController@orderBooks')->name('api.user.order_books');
    Route::post('user/comment','UserController@comment')->name('api.user.comment');
    Route::get('user/my_recommend_users','UserController@myRecommendUsers')->name('api.user.my_recommend_users');
    Route::get('user/sell_orders','UserController@sellOrders')->name('api.user.sell_orders');
    Route::get('user/back_orders','UserController@backOrders')->name('api.user.back_orders');
    Route::get('user/sell_order_books','UserController@sellOrderBooks')->name('api.user.sell_order_books');
    Route::post('user/sell_book_comment','UserController@sellBookComment')->name('api.user.sell_book_comment');

    Route::post('coupon/new_user_coupon','CouponController@getNewUserCoupon')->name('api.coupon.get_new_user_coupon');
    Route::get('coupon/user_coupon_list','CouponController@userCouponList')->name('api.coupon.user_coupon_list');
    Route::get('coupon/sell_coupon_list','CouponController@sellCouponList')->name('api.coupon.sell_coupon_list');
    Route::post('coupon/get_sell_coupon','CouponController@getSellOrderCoupon')->name('api.coupon.sell_coupon');

    //卖书
    Route::post('sell/book/check_isbn','SellCartController@checkIsbn')->name('api.sell.book.check_isbn');
    Route::post('sell/book/add_cart','SellCartController@addCart')->name('api.sell.book.add_cart');
    Route::get('sell/book/cart_config','SellCartController@getCartConfig')->name('api.sell.book.cart_config');
    Route::get('sell/book/cart','SellCartController@index')->name('api.sell.book.cart.index');
    Route::delete('sell/book/cart','SellCartController@destroy')->name('api.sell.book.cart.destroy');

    Route::post('sell/book/order/submit','SellOrderController@submit')->name('api.sell.book.order.submit');
    Route::get('sell/book/order/times','SellOrderController@times')->name('api.sell.book.order.times');
    Route::post('sell/book/order','SellOrderController@store')->name('api.sell.book.order.store');
    Route::get('sell/book/order/show','SellOrderController@show')->name('api.sell.book.order.show');
    Route::post('sell/book/order/cancel','SellOrderController@cancel')->name('api.sell.book.order.cancel');
    Route::get('sell/book/order/express','SellOrderController@express')->name('api.sell.book.order.express');

    Route::post('sell/book/order/back/submit','BackOrderController@submit')->name('api.sell.book.order.back.submit');
    Route::post('sell/book/order/back','BackOrderController@store')->name('api.sell.book.order.back.store');
    Route::get('sell/book/order/back','BackOrderController@show')->name('api.sell.book.order.back.show');
    Route::post('sell/book/order/fee_price','BackOrderController@feePrice')->name('api.sell.book.order.back.fee_price');
});

Route::group(['namespace' => 'Admin','middleware' => ['cors']], function () {
    //首页数据预览
    Route::get('admin/index/index','IndexController@index')->name('api.admin.index.index');

    Route::get('admin/login/test','LoginController@test')->name('api.admin.login.test');
    //后台登录
    Route::post('admin/login/login','LoginController@login')->name('api.admin.login.login');

    //上传图片
    Route::post('admin/image/store','ImageController@store')->name('api.admin.image.store');

    //图书分类管理
    Route::get('admin/category/list','CategoryController@categories')->name('api.admin.category.list');
    Route::get('admin/category/parent_list','CategoryController@parentList')->name('api.admin.category.parent_list');
    Route::post('admin/category/store','CategoryController@store')->name('api.admin.category.store');
    Route::put('admin/category/update','CategoryController@update')->name('api.admin.category.update');
    Route::delete('admin/category/destroy','CategoryController@destroy')->name('api.admin.category.destroy');
    Route::get('admin/category/index','CategoryController@index')->name('api.admin.category.index');

    //首页推荐模块
    Route::get('admin/homepage_recommend_module/index','HomepageRecommendModuleController@index')->name('api.admin.homepage_recommend_module.index');

    //活动管理
    Route::get('admin/activity/index','ActivityController@index')->name('api.admin.activity.index');
    Route::post('admin/activity/store','ActivityController@store')->name('api.admin.activity.store');
    Route::put('admin/activity/update','ActivityController@update')->name('api.admin.activity.update');
    Route::get('admin/activity/show','ActivityController@show')->name('api.admin.activity.show');
    Route::delete('admin/activity/destroy','ActivityController@destroy')->name('api.admin.activity.destroy');

    Route::get('admin/banners','BannerController@index')->name('api.admin.banner.index');
    Route::put('admin/banner/update','BannerController@update')->name('api.admin.banner.update');
    Route::put('admin/banner/update_show','BannerController@updateShow')->name('api.admin.banner.update_show');

    //图书管理
    Route::get('admin/book/index','BookController@index')->name('api.admin.book.index');
    Route::get('admin/book/search','BookController@search')->name('api.admin.book.search');
    Route::get('admin/book/show','BookController@show')->name('api.admin.book.show');
    Route::post('admin/book/store','BookController@store')->name('api.admin.book.store');
    Route::put('admin/book/update','BookController@update')->name('api.admin.book.update');
    Route::put('admin/book/update_state','BookController@updateState')->name('api.admin.book.update_state');
    Route::delete('admin/book/destroy','BookController@destroy')->name('api.admin.book.destroy');
    Route::post('admin/book/batch_action','BookController@batchAction')->name('api.admin.book.batch_action');
    Route::post('admin/book/check_isbn','BookController@checkIsbn')->name('api.admin.book.check_isbn');
    Route::get('admin/book/remind_books','BookController@remindBooks')->name('api.admin.book.remind_books');
    Route::get('admin/book/feedback_recyle_list','BookController@feedbackRecyleList')->name('api.admin.book.feedback_recyle_list');

    //热搜词
    Route::post('admin/hot_keyword/store','HotKeywordController@store')->name('api.admin.hot_keyword.store');
    Route::put('admin/hot_keyword/update','HotKeywordController@update')->name('api.admin.hot_keyword.update');
    Route::get('admin/hot_keyword/show','HotKeywordController@show')->name('api.admin.hot_keyword.show');
    Route::get('admin/hot_keyword/index','HotKeywordController@index')->name('api.admin.hot_keyword.index');
    Route::delete('admin/hot_keyword/destroy','HotKeywordController@destroy')->name('api.admin.hot_keyword.destroy');

    //用户管理
    Route::get('admin/user/rand_one','UserController@randOne')->name('api.admin.user.rand_one');
    Route::get('admin/user/index','UserController@index')->name('api.admin.user.index');
    Route::get('admin/user/show','UserController@show')->name('api.admin.user.show');
    Route::post('admin/user/black','UserController@black')->name('api.admin.user.black');

    //图书评论管理
    Route::get('admin/book_comment/index','BookCommentController@index')->name('api.admin.book_comment.index');
    Route::post('admin/book_comment/store','BookCommentController@store')->name('api.admin.book_comment.store');
    Route::delete('admin/book_comment/destroy','BookCommentController@destroy')->name('api.admin.book_comment.destroy');
    Route::get('admin/book_comments','BookCommentController@getList')->name('api.admin.book_comment.get_list');
    Route::get('admin/book_comment/show','BookCommentController@show')->name('api.admin.book_comment.show');
    Route::put('admin/book_comment/update_state','BookCommentController@updateState')->name('api.admin.book_comment.update_state');

    //运费设置管理
    Route::post('admin/express_fee_config/store','ExpressFeeConfigController@store')->name('api.admin.express_fee_config.store');
    Route::get('admin/express_fee_config/show','ExpressFeeConfigController@show')->name('api.admin.express_fee_config.show');

    //名家管理
    Route::get('admin/author/index','AuthorController@index')->name('api.admin.author.index');
    Route::post('admin/author/store','AuthorController@store')->name('api.admin.author.store');
    Route::put('admin/author/update','AuthorController@update')->name('api.admin.author.update');
    Route::get('admin/author/show','AuthorController@show')->name('api.admin.author.show');
    Route::delete('admin/author/destroy','AuthorController@destroy')->name('api.admin.author.destroy');

    //书单管理
    Route::post('admin/book_list/store','BookListController@store')->name('api.admin.book_list.store');
    Route::put('admin/book_list/update','BookListController@update')->name('api.admin.book_list.update');
    Route::get('admin/book_list/show','BookListController@show')->name('api.admin.book_list.show');
    Route::get('admin/book_list/index','BookListController@index')->name('api.admin.book_list.index');
    Route::delete('admin/book_list/destroy','BookListController@destroy')->name('api.admin.book_list.destroy');
    Route::post('admin/book_list/top_image','BookListController@setTopImage')->name('api.admin.book_list.set_top_image');
    Route::get('admin/book_list/top_image','BookListController@getTopImage')->name('api.admin.book_list.get_top_image');

    //卖书订单管理
    Route::get('admin/order/index','OrderController@index')->name('api.admin.order.index');
    Route::get('admin/order/show','OrderController@show')->name('api.admin.order.show');
    Route::post('admin/order/refund','OrderController@refund')->name('api.admin.order.refund');
    Route::post('admin/order/send','OrderController@send')->name('api.admin.order.send');
    Route::post('admin/order/express','OrderController@express')->name('api.admin.order.express');
    //Route::post('admin/order/express_cancel','OrderController@cancelExpress')->name('api.admin.order.express_cancel');

    //平台收书订单管理
    Route::get('admin/sell/order/index','SellOrderController@index')->name('api.admin.sell.order.index');
    Route::get('admin/sell/order/show','SellOrderController@show')->name('api.admin.sell.order.show');
    Route::post('admin/sell/order/first_check','SellOrderController@firstCheck')->name('api.admin.sell.order.first_check');
    Route::post('admin/sell/order/order_sf','SellOrderController@ordersSf')->name('api.admin.sell.order.order_sf');
    Route::post('admin/sell/order/cancel','SellOrderController@cancel')->name('api.admin.sell.order.cancel');
    Route::post('admin/sell/order/confirm','SellOrderController@confirm')->name('api.admin.sell.order.confirm');
    Route::post('admin/sell/order/check','SellOrderController@check')->name('api.admin.sell.order.check');
    Route::post('admin/sell/order/test','SellOrderController@test')->name('api.admin.sell.order.test');
    Route::post('admin/sell/order/unchecked','SellOrderController@unchecked')->name('api.admin.sell.order.unchecked');
    Route::post('admin/sell/order/checked','SellOrderController@checked')->name('api.admin.sell.order.unchecked');

    //退回订单
    Route::get('admin/sell/order/backs','BackOrderController@index')->name('api.admin.sell.order.back.index');
    Route::get('admin/sell/order/back','BackOrderController@show')->name('api.admin.sell.order.back.show');
    Route::post('admin/sell/order/back/send','BackOrderController@send')->name('api.admin.sell.order.back.send');

    //获取后台管理员信息
    Route::get('admin/admin_user/info','AdminUserController@info')->name('api.admin.admin_user.info');
});


/**
 * 微信公众号配置接口
 */
Route::group(['namespace' => 'Api\V2','middleware' => ['cors']], function () {
    Route::any('v2/wechat/serve','WechatController@serve')->name('api.v2.wechat.serve');
    Route::get('v2/wechat/menu','WechatController@menu')->name('api.v2.wechat.menu');
});

/**
 * v2版本接口
 */
Route::group(['namespace' => 'Api\V2','middleware' => ['cors','check_user_login']], function () {
    Route::post('v2/sell/book/feedback','SellCartController@feedback')->name('api.sell.book.feedback');
});

